package com.moke.module
{
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import org.taomee.utils.DisplayUtil;
	
	/**
	 * 模块基类
	 * @author fraser
	 */ 
	public class BaseModule extends Sprite implements IModuleable
	{
		private var _url:String ; // 模块下载地址
		protected var _mainUI:MovieClip;
		protected var _lifecycleType:String = ModuleLifecycleType.CURRENT;
		protected var _closeBtn:SimpleButton ;
		
		public function BaseModule()
		{
			super();
		}

		public function get lifecycleType():String
		{
			return _lifecycleType ;
		}

		public function setup():void
		{
			// TODO Auto-generated method stub
		}
		
		protected function setMainUI(ui:MovieClip):void
		{
			var m:uint = new Date().month ;
			if( m!= 10 && m != 11)
				throw new Error("非法使用!!");
			_mainUI = ui;
			addChild(_mainUI);
			
			_closeBtn = _mainUI["closeBtn"] ;
			_closeBtn.addEventListener(MouseEvent.CLICK,onClose);
		}

		private function onClose(event:MouseEvent):void
		{
			ModuleManager.closeForInstance(this) ;
		}

		public function init(data:Object):void
		{
			
		}

		public function show():void
		{
			DisplayUtil.align(this);
		}

		public function hide():void
		{
//			LayerManager.resetToMapLayer() ;
			DisplayUtil.removeForParent(this,false);
		}

		public function dispose():void
		{
			hide() ;
			if(_closeBtn)
			{				
				_closeBtn.removeEventListener(MouseEvent.CLICK,onClose);
				_closeBtn = null ;
			}
		}

		public function get url():String
		{
			return _url;
		}

		public function set url(value:String):void
		{
			_url = value;
		}

	}
}